package com.UKIT.airtickets.Activities.other

import TicketAdapter
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.UKIT.airtickets.R
import com.UKIT.airtickets.Service.BottomNavigationHandler
import com.UKIT.airtickets.Service.FetchJsonData
import com.UKIT.airtickets.Service.JsonData
import com.google.android.material.bottomnavigation.BottomNavigationView

class SearchResult: AppCompatActivity(), FetchJsonData.OnDataFetchedListener {
    private lateinit var recyclerView: RecyclerView
    private lateinit var adapter: TicketAdapter
    private lateinit var bottomNavigationHandler: BottomNavigationHandler // Add this line

    @SuppressLint("Range")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.search_result)

        bottomNavigationHandler = BottomNavigationHandler(this)
        val menu = findViewById<BottomNavigationView>(R.id.bottom_navigation)
//        bottomNavigationHandler.setupBottomNavigation(menu)

        recyclerView = findViewById(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(this)
        //adapter = TicketAdapter(this)

        recyclerView.adapter = adapter

        fetchData()
    }

    private fun fetchData() {
        val fetchJsonData = FetchJsonData(this)
        fetchJsonData.fetchTikets()
    }

    override fun onDataFetched(data: JsonData?) {
        data?.let {
            adapter.setData(it.record)
        }
    }
}
